<?php

/**
 * @author liempv
 * @copyright 2012
 */

defined('DSVH') or die('Restricted access');

//add can bo
function insertQuangCao($local){
    mysql_query("insert quang_cao set 
    ten= '".$local['ten']."',
    loai_id = '".$local['loai_id']."',
    link = '".$local['link']."',
    file = '".$local['file']."',
    ben = '".$local['ben']."',
    edit_date = '".$local['edit_date']."',
    user_id = '".$_SESSION['can_bo_id']."',
    status = '".$local['status']."'",
    dbconnect());
}

function getListQuangCao($start, $limit)
    {
    $local_list = mysql_query("SELECT *, qc.edit_date as edit FROM quang_cao qc
    left join loai_quang_cao lqc ON qc.loai_id = lqc.loai_id
    left join can_bo cb ON qc.user_id = cb.can_bo_id
    order by id desc limit  ".(int)$start.",".(int)$limit."
    
    ", dbconnect());
    $result = array();
    while ($local = mysql_fetch_array($local_list)){
        $result []= $local;
    }
    return $result;
    }

function getListLoaiQuangCao($start, $limit)
    {
    $local_list = mysql_query("SELECT * FROM loai_quang_cao
     order by sap_xep desc limit  ".(int)$start.",".(int)$limit."
    
    ", dbconnect());
    $result = array();
    while ($local = mysql_fetch_array($local_list)){
        $result []= $local;
    }
    return $result;
    }

function total(){
   $result = mysql_query("select * from quang_cao",dbconnect());
    return mysql_num_rows($result);
}

//ham lay du lieu tu can bo
function getQuangCao($id)
    {
    $pro = mysql_query("select * from quang_cao where id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
//cap nhat trong thu muc sua
function editQuangCao($id, $local)
{
    $sql = "update quang_cao set 
    ten= '".$local['ten']."',
    link = '".$local['link']."',
    loai_id = '".$local['loai_id']."',
    file = '".$local['file']."',
    ben = '".$local['ben']."',
    edit_date = '".$local['edit_date']."',
    status = '".$local['status']."'
    where id ='".$id."'
    ";
    
    mysql_query($sql, dbconnect());
}   
// xoa thu muc
 function delQuangCao($id){
    mysql_query("delete from quang_cao where id= '".(int)$id."'", dbconnect());
}


    
// kiem tra da ton tai
 function check_exist_local($name){
    $sql = "SELECT * FROM can_bo where ten_can_bo = '".$name."'";
    $location = mysql_query($sql, dbconnect());
    return mysql_num_rows($location);

}
 function check_email($email){
    $sql = "SELECT * FROM can_bo where email = '".$email."'";
    $location = mysql_query($sql, dbconnect());
    return mysql_num_rows($location);

}
 function check_dn($dn){
    $sql = "SELECT * FROM can_bo where ten_dang_nhap = '".$dn."'";
    $location = mysql_query($sql, dbconnect());
    return mysql_num_rows($location);

}

function getAdmin($u,$pwd){
    $sql = "SELECT * FROM can_bo where ten_dang_nhap = '".escape($u)."' and mat_khau = '".escape($pwd)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_fetch_array($result);
} 

function login($u,$pwd){
    $sql = "SELECT * FROM can_bo where ten_dang_nhap = '".escape($u)."' and mat_khau = '".escape($pwd)."' limit 0,1";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
} 

function check_login($u,$pwd){
    $sql = "SELECT * FROM can_bo where ten_dang_nhap = '".$u."' and mat_khau = '".$pwd."' and status ='1' ";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
} 
function getListLog($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM  nhat_ki order by id desc limit  ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }

 function delLog($id){
    mysql_query("delete from nhat_ki where id= '".(int)$id."'", dbconnect());
}

function totalLog(){
   $result = mysql_query("select * from nhat_ki",dbconnect());
    return mysql_num_rows($result);
}

function getListBaoCaoHV($start, $limit)
    {
        $local_list = mysql_query("SELECT * FROM  ho_so_hien_vat 
        left join can_bo ON ho_so_hien_vat.can_bo_id = can_bo.can_bo_id
        order by ho_so_id desc limit  ".(int)$start.",".(int)$limit."", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }




?>